﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using DataSourceRequest = Kendo.Mvc.UI.DataSourceRequest;

using netEntity = tuReserva.Model;
using tuReserva.Service;

namespace tuReserva.com.Controllers
{
    public class OwnerController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

		public ActionResult getPartials(string partial)
		{
			return View(partial);
		}

		public JsonResult getRestaurantList([DataSourceRequest]DataSourceRequest request)
		{
			netEntity.User u = Session["User"] as netEntity.User;

			List<netEntity.Restaurant> restaurantList = new ApplicationService().getRestaurantList(u);

			var data = restaurantList.ToDataSourceResult(request);

			return new JsonResult { Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; 
		}

		public JsonResult getNewRestaurant()
		{
			return Json(new netEntity.Restaurant(), JsonRequestBehavior.AllowGet);
		}

		public void saveRestaurant(netEntity.Restaurant restaurant)
		{
			restaurant.User = Session["User"] as netEntity.User;

			if (restaurant.isNew)
			{
				new ApplicationService().insertRestaurant(restaurant);
			}
		}

		public JsonResult getCategoryList()
		{
			List<netEntity.Category> list = new ApplicationService().getCategoryList();

			return Json(list, JsonRequestBehavior.AllowGet);
		}

		public JsonResult getLoadedReserveList([DataSourceRequest]DataSourceRequest request)
		{
			netEntity.User u = Session["User"] as netEntity.User;

			List<netEntity.Reserve> reserveList = new ApplicationService().getLoadedReserveList(u);

			var data = reserveList.ToDataSourceResult(request);

			return new JsonResult { Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
		}

		public void updateReserve(netEntity.Reserve r)
		{
			new ApplicationService().updateReserve(r);
		}
    }
}
